package com.api.shopapi.mapper;

import com.api.shopapi.entity.DishesPlan;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface DishesPlanMapper {


    @Insert("insert into dishes_plan" +
            "(" +
            "DishesPlanCode," +
            "Day," +
            "Time," +
            "CreateTime," +
            "Status," +
            "CarePlaceCode" +
            ") " +
            "values" +
            "(" +
            "#{dishesPlan.DishesPlanCode}," +
            "#{dishesPlan.Day}," +
            "#{dishesPlan.Time}," +
            "#{dishesPlan.CreateTime}," +
            "#{dishesPlan.Status}," +
            "#{dishesPlan.CarePlaceCode}" +
            ")")
    int insert(@Param("dishesPlan") DishesPlan dishesPlan);

    @Delete("delete from dishes_plan where dishesPlanCode=#{dishesPlanCode}")
    int delete(@Param("dishesPlanCode") String dishesPlanCode);

    @Update("update dishes_plan" +
            " set" +
            " Day=#{dishesPlan.Day}," +
            " Status=#{dishesPlan.Status}," +
            " Time=#{dishesPlan.Time}" +
            " where " +
            " dishesPlanCode=#{dishesPlan.dishesPlanCode}")
    int update(@Param("dishesPlan") DishesPlan dishesPlan);

    @Select("select * from dishes_plan where dishesPlanCode=#{dishesPlanCode} limit 1")
    DishesPlan getByDishesPlanCode(@Param("dishesPlanCode") String dishesPlanCode);

    @Select("<script>" +
            "select * from dishes_plan where carePlaceCode=#{carePlaceCode} order by createTime desc" +
            "</script>")
    List<DishesPlan> ListByCarePlaceCode(@Param("carePlaceCode") String carePlaceCode);


}
